package com.rabbiter.oes.controller;

import com.rabbiter.oes.entity.MultiQuestion;
import com.rabbiter.oes.result.R;
import com.rabbiter.oes.service.impl.MultiQuestionServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "选择题")
@RestController
public class MultiQuestionController {

    @Autowired
    private MultiQuestionServiceImpl multiQuestionService;

    @ApiOperation(value = "获取最后一条选择题", notes = "获取最后一条选择题", httpMethod = "GET")
    @GetMapping("/multiQuestionId")
    public R findOnlyQuestion() {
        MultiQuestion res = multiQuestionService.findOnlyQuestionId();
        return R.ok("查询成功").data(res);
    }

    @ApiOperation(value = "添加选择题", notes = "添加选择题", httpMethod = "POST")
    @PostMapping("/MultiQuestion")
    public R add(@RequestBody MultiQuestion multiQuestion) {
        Integer questionId = multiQuestionService.add(multiQuestion);
        if (questionId != 0) {
            return R.ok("添加成功").data(questionId);
        }
        return R.logicError("添加失败").data(questionId);
    }

    @ApiOperation(value = "修改选择题", notes = "修改选择题", httpMethod = "POST")
    @PostMapping("/editMultiQuestion")
    public R edit(@RequestBody MultiQuestion multiQuestion) {
        int res = multiQuestionService.edit(multiQuestion);
        if (res != 0) {
            return R.ok("修改成功").data(res);
        }
        return R.logicError("修改失败").data(res);
    }
}
